package org.lanqiao.ssm.web.auth.controller;

import java.util.List;

import org.lanqiao.ssm.common.facede.BaseManagerFacedeI;
import org.lanqiao.ssm.common.facede.BaseQueryFacedeI;
import org.lanqiao.ssm.common.model.Json;
import org.lanqiao.ssm.common.web.controller.BaseController;
import org.lanqiao.ssm.facede.auth.facede.ResourceManagerFacedeI;
import org.lanqiao.ssm.facede.auth.facede.ResourceQueryFacedeI;
import org.lanqiao.ssm.facede.auth.model.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@SuppressWarnings("all")
@RestController
@RequestMapping("/resource")
public class ResourceController extends
		BaseController<Resource, String>  {
	@javax.annotation.Resource
	private ResourceManagerFacedeI resourceManagerFacede;
	@javax.annotation.Resource
	private ResourceQueryFacedeI resourceQueryFacede;

	@Override
	public BaseManagerFacedeI<Resource, String> getManagerFacede() {
		return resourceManagerFacede;
	}

	@Override
	public BaseQueryFacedeI<Resource, String> getQueryFacede() {
		return resourceQueryFacede;
	}

	@RequestMapping(value = "/findAllTreeNode", method = RequestMethod.GET)
	public List<Resource> findAllTreeNode() {
		return resourceQueryFacede.findAllTreeNode();
	}

	@RequestMapping(value = "/treegrid", method = RequestMethod.GET)
	public List<Resource> treegrid() {
		return resourceQueryFacede.treegrid();
	}

	@RequestMapping(value = "/remove", method = RequestMethod.POST)
	public Json remove(String id) {
		return resourceManagerFacede.remove(id) > 0 ? setSimpleSuccess(id)
				: setFailed();
	}

	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public Json add(Resource r) {

		return resourceManagerFacede.add(r) > 0 ? setSimpleSuccess(r)
				: setFailed();
	}

	@RequestMapping(value = "/edit", method = RequestMethod.POST)
	public Json edit(Resource r) {

		return resourceManagerFacede.edit(r) > 0 ? setSimpleSuccess(r)
				: setFailed();
	}

}
